package com.fifth.apartment.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fifth.apartment.entity.Bills;
import com.fifth.apartment.vo.room.RoomAptVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author author
 * @since 2024-07-24
 */
@Mapper
public interface BillsMapper extends BaseMapper<Bills> {

    @Select("select * from bills where user_info_id = #{userId}")
    Bills getBills(int userId);

    @Select("SELECT room_number as room , bi.name as building FROM user_room ur " +
            "INNER join room_info ri on room_id = ri.id " +
            "inner join building_info bi on apartment_id = bi.id " +
            "where ur.user_id = #{userId}")
    RoomAptVo getRoomApt(int userId);

    @Select("SELECT water_value from bills where user_info_id = #{userId}; ")
    Integer getWaterValue(int userId);

    @Update("UPDATE bills set water_value = 0 where id = #{userId}")
    Integer updateWaterValue(Integer userId);

    @Update("update bills set outTradeNo = #{outTradeNo} where id = #{userId}")
    void updateOutTradeNo(Integer userId, long outTradeNo);

    @Select("select id from bills where outTradeNo = #{outTradeNo}")
    Integer getUserId(String outTradeNo);
}
